﻿using System;
using Macds.Core.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Macds.Test.Core.Serialization
{
    [TestClass]
    public class ConverterTest
    {
        [TestMethod]
        public void Get_bytes_from_object()
        {
            // Create instance of the customer model class
            var customerModel = new Mocks.CustomerModel() { FirstName = "John", LastName = "Smith" };

            // serialize object to byte array
            byte[] data = Converter.GetBytesFromObject(customerModel);

            // Validate
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 0);
        }

        [TestMethod]
        public void Get_object_from_bytes()
        {
            // Create instance of the serialize customer model class in byte array
            var data = Mocks.CustomerModel.Data;

            // deserialize byte array to customer model class
            var customerModel = (Mocks.CustomerModel)Converter.GetObjectFromBytes(data);

            // Validate
            Assert.AreEqual("John", customerModel.FirstName);
            Assert.AreEqual("Smith", customerModel.LastName);
        }
    }
}
